package com.scm.servlet.system;

import java.io.IOException;
import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



import org.apache.log4j.Logger;

import com.scm.model.ScmUser;
import com.scm.page.Page;
import com.scm.service.ScmuserService;
import com.scm.servlet.report.FinanceReportDetailServlet;
/**
 * 用户管理首页
 * @author Surrik_Zhang
 *
 */
@WebServlet("/main/system/scmuserShow")
public class ScmuserShowServlet extends HttpServlet{
	private static final Logger LOGGER = Logger.getLogger(ScmuserShowServlet.class);
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		//获取当前页码参数
		String currentPageStr = req.getParameter("currentPage");
		int currentPage = 1;//默认当前页码为第一页
		try{
			if(currentPageStr != null && currentPageStr.matches("\\d+")){
				currentPage = Integer.parseInt(currentPageStr);
			}
		}catch(NumberFormatException e){
			//参数不是数字或者没有该参数时，默认访问第一页
			currentPage = 1;
		}
		
		Map<String,String> queryCondition = new HashMap<String,String>();
		queryCondition.put("account", req.getParameter("account"));
		queryCondition.put("name", req.getParameter("name"));
		queryCondition.put("startDate", req.getParameter("startDate"));
		queryCondition.put("endDate", req.getParameter("endDate"));
		queryCondition.put("status", req.getParameter("status"));
		LOGGER.info("[查询条件]-->"+queryCondition);
		
		try {
			Page<ScmUser> page = new ScmuserService().selectScmuser(queryCondition, currentPage);
			
			req.setAttribute("page", page);
//			req.setAttribute("queryCondition", queryCondition);
			
//			req.getRequestDispatcher("/main/system/scmuser_layer.jsp").forward(req, resp);
		} catch (Exception e) {
			LOGGER.error("用户管理首页异常",e);
		}
		req.getRequestDispatcher("/main/system/scmuser.jsp").forward(req, resp);
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}
}
